<?php 
class RoleAction extends CommonAction{
	//角色列表
	public function roleList()
	{
		$role=M('Role');
		$role_info=$role->select();
		
		$this->assign('role_info',$role_info);
		$this->display();
	}
	
	//授权页面显示
	public  function privilege()
	{
		$rid=$_GET['rid']+0;
		if(!isset($_GET['nid']))
		{
			$nid=0;
		}
		else
		{
			$nid=$_GET['nid']+0;
		}
		$flag=isset($_GET['flag'])?$_GET['flag']:"first";
		if($flag=="first") $nflag="second";
		elseif($flag=="second") $nflag="third";
		else $nflag=true;
    
		$node=D('Role');
		$node_info=$node->getRoleList($flag,$nid,$rid);
	
		$this->assign('node_info',$node_info);
		$this->assign('rid',$rid);
		$this->assign('flag',$nflag);
		$this->display();
	}
	
	//授权及取消
	public function cancel()
	{
		$nid=isset($_GET['nid'])?$_GET['nid']:0;
		$nid=$nid+0;
		$flag=isset($_GET['flag'])?$_GET['flag']:"first";
		$access=M('Access');
	
		if(	$access->where("node_id=$nid")->delete())
		{
				//$this->assign('jumpUrl','__URL__/privilege');
      	$this->success("取消授权成功");
		}
		else
		{
			$this->error("取消授权失败，请于管理员联系");
		}
	}
	
	//进行授权
	public function act()
	{
		$nid=isset($_GET['nid'])?$_GET['nid']+0:0;
		//$nid=$nid+0;
		$rid=$_GET['rid']+0;
		$flag=isset($_GET['flag'])?$_GET['flag']:"first";
		
		$access=M('Access');
		$node= M('Node');
		$node_info=$node->where("id=$nid")->find();
    
		$data['role_id']=$rid;
		$data['node_id']=$node_info['id'];
		$data['level']=$node_info['level'];
		$data['pid']=$node_info['pid'];
  
		if($access->data($data)->add())
		{
	  	//$this->assign('jumpUrl','__URL__/privilege');
		$this->success("授权成功");
		}
		else
		{
			$this->error("授权失败，请于管理员联系");
		}
	  
	}
}


?>